using NUnit.Framework;

namespace ValidationFramework.Tests
{
    [TestFixture]
    public class RequiredDecimalRuleAttributeTest
    {
        [Test]
        public void CheckDefaultValues()
        {
            var ruleAttribute = new RequiredDecimalRuleAttribute();
            
			var propertyRule = (RequiredRule<decimal>)ruleAttribute.CreateInstance(new MockPropertyDescriptor<decimal>("foo"));
            var parameterRule = (RequiredRule<decimal>)ruleAttribute.CreateInstance(new MockParameterDescriptor<decimal>("foo"));
            var fieldRule = (RequiredRule<decimal>)ruleAttribute.CreateInstance(new MockFieldDescriptor<decimal>("foo"));

        }

        [Test]
        public void CheckNonDefaultValues()
        {
            var ruleAttribute = new RequiredDecimalRuleAttribute();
            const decimal expectedInitialValueDecimal = 3;
            const double expectedInitialValueDouble = 3;
            ruleAttribute.InitialValue = expectedInitialValueDouble;
            Assert.AreEqual(expectedInitialValueDouble, ruleAttribute.InitialValue);

            var propertyRule = (RequiredRule<decimal>)ruleAttribute.CreateInstance(new MockPropertyDescriptor<decimal>("foo"));
            var parameterRule = (RequiredRule<decimal>)ruleAttribute.CreateInstance(new MockParameterDescriptor<decimal>("foo"));
            var fieldRule = (RequiredRule<decimal>)ruleAttribute.CreateInstance(new MockFieldDescriptor<decimal>("foo"));

            Assert.AreEqual(expectedInitialValueDecimal, propertyRule.InitialValue);

            Assert.AreEqual(expectedInitialValueDecimal, parameterRule.InitialValue);

            Assert.AreEqual(expectedInitialValueDecimal, fieldRule.InitialValue);
        }


        [Test]
        public void CallAttributeTester()
        {
            AttributeTester.CheckDefaultValues<decimal>(new RequiredDecimalRuleAttribute(), true, true, true);
            AttributeTester.CheckNonDefaultValues<decimal>(new RequiredDecimalRuleAttribute(), true, true, true);
        }
    }
}